import Vue from 'vue';
import Router from 'vue-router';
import Home from '@/views/Home.vue';

const NotFound = import('./components/modules/NotFound.vue');
const Login = () => import(/* webpackChunkName: 'login' */ './views/Login.vue');
const Reg = () => import(/* webpackChunkName: 'reg' */ './views/Reg.vue');
const Forget = () => import(/* webpackChunkName: 'forget' */ './views/Forget.vue');
const Index = () => import(/* webpackChunkName: 'index' */ './views/channels/index.vue');
const Template1 = () => import(/* webpackChunkName: 'template1' */ './views/channels/template1.vue');
const Center = () => import(/* webpackChunkName: 'center' */ './views/Center.vue');
const UserCenter = () => import(/* webpackChunkName: 'UserCenter' */ './views/center/Center.vue');
const UserPosts = () => import(/* webpackChunkName: 'UserPosts' */ './views/center/Posts.vue');
const UserSettings = () => import(/* webpackChunkName: 'UserSettings' */ './views/center/Settings.vue');
const UserMsg = () => import(/* webpackChunkName: 'UserMsg' */ './views/center/Msg.vue');
const UserOthers = () => import(/* webpackChunkName: 'UserOthers' */ './views/center/Others.vue');
const UserIndex = () => import(/* webpackChunkName: 'UserCenter' */ './views/center/User.vue');
const MyInfo = () => import(/* webpackChunkName: 'MyInfo' */ './views/center/common/MyInfo.vue');
const PicUpload = () => import(/* webpackChunkName: 'PicUpload' */ './views/center/common/PicUpload.vue');
const Passwd = () => import(/* webpackChunkName: 'Passwd' */ './views/center/common/Passwd.vue');
const Accounts = () => import(/* webpackChunkName: 'Accounts' */ './views/center/common/Accounts.vue');
const MyPosts = () => import(/* webpackChunkName: 'MyPosts' */ './views/center/common/MyPosts.vue');
const MyCollections = () => import(/* webpackChunkName: 'MyCollections' */ './views/center/common/MyCollections.vue');

Vue.use(Router);

export default new Router({
  linkExactActiveClass: 'layui-this',
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login
    }, {
      path: '/reg',
      name: 'Reg',
      component: Reg,
      beforeEnter: (to, from, next) => {
        if (from.name === 'Login') {
          next();
        } else {
          next('/login');
        }
      }
    }, {
      path: '/forget',
      name: 'Forget',
      component: Forget
    }, {
      path: '/',
      // name: 'index',
      component: Home,
      children: [{
        path: '',
        redirect: '/index'
      }, {
        path: 'index',
        name: 'HomeIndex',
        component: Index
      }, {
        path: 'index/:catalog',
        name: 'template1',
        component: Template1
      }]
    }, {
      path: '/center',
      component: Center,
      linkActiveClass: 'layui-this',
      children: [{
        path: '',
        redirect: 'center'
      }, {
        name: 'Center',
        component: UserCenter,
        path: 'center'
      }, {
        name: 'Posts',
        path: 'posts',
        component: UserPosts,
        children: [{
          path: '',
          name: 'mypost',
          component: MyPosts
        }, {
          path: 'collection',
          name: 'collection',
          component: MyCollections
        }]
      }, {
        name: 'Settings',
        path: 'settings',
        component: UserSettings,
        children: [{
          path: '',
          name: 'info',
          component: MyInfo
        }, {
          path: 'pic',
          name: 'pic',
          component: PicUpload
        }, {
          path: 'passwd',
          name: 'passwd',
          component: Passwd
        }, {
          path: 'accounts',
          name: 'accounts',
          component: Accounts
        }]
      }, {
        name: 'Others',
        path: 'others',
        component: UserOthers
      }, {
        name: 'Msg',
        path: 'msgs',
        component: UserMsg
      }]
    }, {
      name: 'User',
      path: '/user/:uid',
      component: UserIndex,
      props: true
    }, {
      name: 'NotFound',
      path: '*',
      component: NotFound
    }
  ]
});
